#include "pageeventsidenavi.h"
#include "ui_pageeventsidenavi.h"

PageEventSideNavi::PageEventSideNavi(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::PageEventSideNavi)
{
    ui->setupUi(this);
    setAutoFillBackground(true);  //设置自动填充
    QPalette palette = BKGCLR;
    setPalette(palette);

    m_lNaviBtnName<<"现存故障"
                  <<"故障履历";
    InitBtns();
}

PageEventSideNavi::~PageEventSideNavi()
{
    delete ui;
}

void PageEventSideNavi::InitBtns()
{
    uint8_t navibtncnt = m_lNaviBtnName.length();
    m_nNaviBtnLen = 110;
    m_nNaviBtnHeight = 50;
    m_nVSpace = 15;
    m_nStartx = (this->width()-m_nNaviBtnLen)/2;
    m_nStarty = (this->height()-(navibtncnt+1)*m_nNaviBtnHeight-(navibtncnt-1)*m_nVSpace)/2;

    for(uint i=0;i<navibtncnt;i++)
    {
        QPushButton *btn = new QPushButton(this);
        btn->setStyleSheet(SideNaviBtnStyle);
        btn->setGeometry(m_nStartx,m_nStarty+i*(m_nNaviBtnHeight+m_nVSpace),
                         m_nNaviBtnLen,m_nNaviBtnHeight);
        btn->setText(m_lNaviBtnName.at(i));
        btn->setCheckable(true);
        btn->setChecked(i==0);
        m_cNaviBtnGroup.addButton(btn,i+Page_Event_Cur);
    }
    connect(&m_cNaviBtnGroup,SIGNAL(buttonClicked(int)),this,SIGNAL(signal_show_event_page(int)));

    QPushButton *HintBtn = new QPushButton(this);
    HintBtn->setStyleSheet(SideNaviBtnStyle);
    HintBtn->setGeometry(m_nStartx,m_nStarty+2*(m_nNaviBtnHeight+m_nVSpace),
                     m_nNaviBtnLen,m_nNaviBtnHeight);
    HintBtn->setText("操作提示");
    HintBtn->setCheckable(false);
    connect(HintBtn,SIGNAL(clicked()),this,SIGNAL(signal_show_event_hint()));
}

void PageEventSideNavi::ResetBtnCheckStat()
{
    QAbstractButton* btnChecked = m_cNaviBtnGroup.checkedButton();
    btnChecked->setChecked(false);
    QAbstractButton* firstBtn = m_cNaviBtnGroup.button(Page_Event_Cur);
    firstBtn->setChecked(true);
}

int PageEventSideNavi::EventBtnId() const
{
    return m_cNaviBtnGroup.checkedId();
}
